package com.ams.misc;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ams.io.BufferOutputStream;
import com.ams.io.RandomAccessFileReader;
import com.ams.io.RandomAccessFileWriter;
import com.ams.media.flv.FlvDeserializer;

public class MakeFlvIndex {
    final static private Logger logger = LoggerFactory
            .getLogger(MakeFlvIndex.class);

    public static void main(String[] args) {
        if (args.length < 1) {
            System.out.println("MakeFlvIndex.main fileName");
            return;
        }
        String fileName = args[0];

        try {
            logger.info("Start creating index...");
            RandomAccessFileReader reader = new RandomAccessFileReader(
                    fileName, 0);
            FlvDeserializer flvDeserializer = new FlvDeserializer(reader);
            flvDeserializer.readSamples();
            RandomAccessFileWriter writer = new RandomAccessFileWriter(fileName
                    + ".idx", false);
            FlvDeserializer.FlvIndex flvIndex = flvDeserializer.new FlvIndex();
            BufferOutputStream bos = new BufferOutputStream(writer);
            flvIndex.write(bos);
            bos.flush();
            bos.close();
            logger.info("End creating index");
        } catch (IOException e) {
            e.printStackTrace();
            logger.debug(e.toString());
        }
    }
}
